package network;

import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * Created with IntelliJ IDEA
 * Description:InetAddress学习
 * User:22954
 * Date:2024-04-01
 * Time:19:16
 */
public class InetAddress_ {
    /*
    static InetAddress getLocalHost()   获取本机 InetAddress / ip地址 对象
    static InetAddress getByName(String host)   根据指定 主机名 / 域名 获取ip地址对象
    String getHostAddress()    获取InetAddress对象的地址
    String getHostName()    获取InetAddress对象的主机名
     */
    public static void main(String[] args) throws UnknownHostException {
        InetAddress inetAddress = InetAddress.getLocalHost();
        System.out.println(inetAddress);//LI_SHEN/10.122.229.191

        inetAddress = InetAddress.getByName("LI_SHEN");
        System.out.println(inetAddress);//LI_SHEN/10.122.229.191

        InetAddress host = InetAddress.getByName("www.baidu.com");
        System.out.println(host);//www.baidu.com/220.181.38.149

        String hostAddress = host.getHostAddress();
        System.out.println(hostAddress);//220.181.38.149

        String hostName = host.getHostName();
        System.out.println(hostName);//www.baidu.com
    }
}
